/*
 * MainFrame.java
 *
 * Created on 18 יוני 2008, 20:49
 */

package Presentation;

import assemblydecoder.Command;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Image;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.border.TitledBorder;

/**
 *
 * @author  shai
 */
public class MainFrame extends javax.swing.JFrame {
    
    //static Image image = Toolkit.getDefaultToolkit().getImage("maggie.GIF");
    static TrayIcon trayIcon;
    static URL url;
    static ImageIcon imageIcon;
    static Image image;
    
    /** Creates new form MainFrame */
    public MainFrame() {
        url = getClass().getClassLoader().getResource("images/maggie.GIF");
        imageIcon = new ImageIcon(url);
        image = imageIcon.getImage();
        trayIcon = new TrayIcon(image, "Assembler Decoder for SRC (by shaigi)");
        
        initComponents();
        setFrameAtCenter(this);
        createSystemTrayIcon();
        //this.setAlwaysOnTop(true);
        this.jTextFieldInputCommand.requestFocus();
    }
    
    public static void setFrameAtCenter(JFrame frame){
        int width = frame.getWidth();
        int height = frame.getHeight();
        frame.setResizable(false);
        Toolkit t = Toolkit.getDefaultToolkit();
        int x = (int)((t.getScreenSize().getWidth() - width) / 2);
        int y = (int)((t.getScreenSize().getHeight() - height) / 2);
        frame.setLocation(x, y);
    }
    
    private void createSystemTrayIcon(){
        if (SystemTray.isSupported()) {
            SystemTray tray = SystemTray.getSystemTray();

            trayIcon.setImageAutoSize(true);
            trayIcon.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    setVisible(!isVisible());
                    trayIcon.displayMessage("Assembler Decoder for SRC!", "01001110101011?", TrayIcon.MessageType.INFO);
                }
            });
            try {
                tray.add(trayIcon);
            } catch (AWTException e) {
                System.err.println("TrayIcon could not be added.");
            }
        }
    }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel6 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldInputCommand = new javax.swing.JTextField();
        jPanelOpcode = new javax.swing.JPanel();
        jLabelOpcode = new javax.swing.JLabel();
        jPanelRa = new javax.swing.JPanel();
        jLabelRa = new javax.swing.JLabel();
        jPanelRb = new javax.swing.JPanel();
        jLabelRb = new javax.swing.JLabel();
        jPanelRc = new javax.swing.JPanel();
        jLabelRc = new javax.swing.JLabel();
        jPanelNumber = new javax.swing.JPanel();
        jLabelNumber = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabelC2 = new javax.swing.JLabel();
        jLabelC1 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabelC3 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jLabelAnswer = new javax.swing.JLabel();
        jLabelAnswerCommandName = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Hexa Command:");

        jTextFieldInputCommand.setToolTipText("Insert 8 hexa digits");

        jPanelOpcode.setBorder(javax.swing.BorderFactory.createTitledBorder("Opcode"));

        jLabelOpcode.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabelOpcode.setText("00000");

        javax.swing.GroupLayout jPanelOpcodeLayout = new javax.swing.GroupLayout(jPanelOpcode);
        jPanelOpcode.setLayout(jPanelOpcodeLayout);
        jPanelOpcodeLayout.setHorizontalGroup(
            jPanelOpcodeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOpcodeLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelOpcode)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelOpcodeLayout.setVerticalGroup(
            jPanelOpcodeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOpcodeLayout.createSequentialGroup()
                .addComponent(jLabelOpcode)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jPanelRa.setBorder(javax.swing.BorderFactory.createTitledBorder("Ra"));

        jLabelRa.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabelRa.setText("00000");

        javax.swing.GroupLayout jPanelRaLayout = new javax.swing.GroupLayout(jPanelRa);
        jPanelRa.setLayout(jPanelRaLayout);
        jPanelRaLayout.setHorizontalGroup(
            jPanelRaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelRaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelRa)
                .addContainerGap(13, Short.MAX_VALUE))
        );
        jPanelRaLayout.setVerticalGroup(
            jPanelRaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelRaLayout.createSequentialGroup()
                .addComponent(jLabelRa)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jPanelRb.setBorder(javax.swing.BorderFactory.createTitledBorder("Rb"));

        jLabelRb.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabelRb.setText("00000");

        javax.swing.GroupLayout jPanelRbLayout = new javax.swing.GroupLayout(jPanelRb);
        jPanelRb.setLayout(jPanelRbLayout);
        jPanelRbLayout.setHorizontalGroup(
            jPanelRbLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelRbLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelRb)
                .addContainerGap(13, Short.MAX_VALUE))
        );
        jPanelRbLayout.setVerticalGroup(
            jPanelRbLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelRbLayout.createSequentialGroup()
                .addComponent(jLabelRb)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jPanelRc.setBorder(javax.swing.BorderFactory.createTitledBorder("Rc"));

        jLabelRc.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabelRc.setText("00000");

        javax.swing.GroupLayout jPanelRcLayout = new javax.swing.GroupLayout(jPanelRc);
        jPanelRc.setLayout(jPanelRcLayout);
        jPanelRcLayout.setHorizontalGroup(
            jPanelRcLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelRcLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelRc)
                .addContainerGap(13, Short.MAX_VALUE))
        );
        jPanelRcLayout.setVerticalGroup(
            jPanelRcLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelRcLayout.createSequentialGroup()
                .addComponent(jLabelRc)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jPanelNumber.setBorder(javax.swing.BorderFactory.createTitledBorder("Number"));

        jLabelNumber.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabelNumber.setText("000000000000");

        javax.swing.GroupLayout jPanelNumberLayout = new javax.swing.GroupLayout(jPanelNumber);
        jPanelNumber.setLayout(jPanelNumberLayout);
        jPanelNumberLayout.setHorizontalGroup(
            jPanelNumberLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelNumberLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelNumber)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelNumberLayout.setVerticalGroup(
            jPanelNumberLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelNumberLayout.createSequentialGroup()
                .addComponent(jLabelNumber)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jLabel7.setFont(new java.awt.Font("Comic Sans MS", 1, 24)); // NOI18N
        jLabel7.setText("Assembly Decoder for SRC");

        jButton1.setText("Decode");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel3.setText("Number C2 (Including Rc):");

        jLabel4.setText("Number C1 (Including Rb & Rc):");

        jLabelC2.setText("0");

        jLabelC1.setText("0");

        jLabel5.setText("Number C3 (5 lsb bits):");

        jLabelC3.setText("0");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Answer"));

        jLabelAnswer.setFont(new java.awt.Font("Tahoma", 1, 24));
        jLabelAnswer.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);

        jLabelAnswerCommandName.setFont(new java.awt.Font("Tahoma", 1, 24));
        jLabelAnswerCommandName.setForeground(new java.awt.Color(255, 0, 51));
        jLabelAnswerCommandName.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(146, Short.MAX_VALUE)
                .addComponent(jLabelAnswerCommandName, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelAnswer, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(45, 45, 45))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabelAnswer, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE)
                    .addComponent(jLabelAnswerCommandName, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30))
        );

        jLabel2.setText("(by shaigi)");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(7, 7, 7)
                                .addComponent(jTextFieldInputCommand, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton1))
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addComponent(jPanelOpcode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPanelRa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPanelRb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPanelRc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPanelNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel4))
                                .addGap(35, 35, 35)
                                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabelC2, javax.swing.GroupLayout.DEFAULT_SIZE, 45, Short.MAX_VALUE)
                                    .addComponent(jLabelC1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabelC3)))
                            .addComponent(jLabel5)
                            .addGroup(jPanel6Layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(101, 101, 101)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)))
                .addContainerGap(11, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel2))
                .addGap(23, 23, 23)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldInputCommand, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelOpcode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanelNumber, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jPanelRb, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanelRa, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jPanelRc, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addComponent(jLabelC2)
                        .addGap(7, 7, 7)
                        .addComponent(jLabelC1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabelC3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, 574, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    String command = this.jTextFieldInputCommand.getText();
    Command c = null;
    this.jLabelAnswerCommandName.setText("");
    this.jLabelAnswer.setText("");
    try {
        //try {
            c = new Command(command);
        //} catch (Exception ex) {
        //   JOptionPane.showMessageDialog(null, ex.getMessage(), "Error...", JOptionPane.ERROR_MESSAGE);
        //}
        this.jLabelOpcode.setText(c.getOpcodeBinary());
        this.jLabelRa.setText(c.getRaBinary());
        this.jLabelRb.setText(c.getRbBinary());
        this.jLabelRc.setText(c.getRcBinary());
        this.jLabelNumber.setText(c.getNumberBinary());
        this.jLabelC2.setText(""+c.getNumberC2());
        this.jLabelC1.setText(""+c.getNumberC1());
        this.jLabelC3.setText(""+c.getNumberC3());
        
        TitledBorder t = new TitledBorder(""+c.getOpcodeName());
        t.setTitleColor(Color.RED);
        this.jPanelOpcode.setBorder(t);
        this.jPanelRa.setBorder(new TitledBorder("R"+c.getRa()));
        this.jPanelRb.setBorder(new TitledBorder("R"+c.getRb()));
        this.jPanelRc.setBorder(new TitledBorder("R"+c.getRc()));
        this.jPanelNumber.setBorder(new TitledBorder(""+c.getNumber()));
        
        int opcode = (int)c.getOpcode();
        System.out.println("opcode: "+opcode);
        jLabelAnswerCommandName.setText(c.getOpcodeName());
        
        int[] raNotExists = {0, 8, 31};
        Vector raNotExistsVector = arrayToVector(raNotExists);
        if (!raNotExistsVector.contains(opcode)) {
            jLabelAnswer.setText("r"+c.getRa());
        }
        
        int[] rbExists = {1, 3, 5, 8, 9, 12, 13, 14, 20, 21, 22, 23, 25, 26, 27, 28, 29};
        Vector rbExistsVector = arrayToVector(rbExists);
        System.out.println("rbExistsVector: "+rbExistsVector);
        if (rbExistsVector.contains(opcode)){
            if (opcode == 1 ||opcode == 3 || opcode == 5){
                if (c.getRb() != 0){
                    jLabelAnswer.setText(jLabelAnswer.getText() + " r"+c.getRb());
                }
            } else if (opcode == 9 && c.getNumberC3() >= 2 && c.getNumberC3() <= 5){
                jLabelAnswer.setText(jLabelAnswer.getText() + " r"+c.getRb());
            } else{
                jLabelAnswer.setText(jLabelAnswer.getText() + " r"+c.getRb());
            }
        }
        
        int[] c2Exists = {1, 3, 5, 11, 13, 21, 23};
        Vector c2ExistsVector = arrayToVector(c2Exists);
        if (c2ExistsVector.contains(new Integer(opcode))) {
            jLabelAnswer.setText(jLabelAnswer.getText() + " "+c.getNumberC2());
        }
        
        int[] c1Exists = {2, 4, 6};
        Vector c1ExistsVector = arrayToVector(c1Exists);
        if (c1ExistsVector.contains(new Integer(opcode))) {
            jLabelAnswer.setText(jLabelAnswer.getText() + " "+c.getNumberC1());
        }
        
        int[] rcExists = {8, 9, 12, 14, 15, 20, 22, 24, 26, 27, 28, 29};
        Vector rcExistsVector = arrayToVector(rcExists);
        if (rcExistsVector.contains(new Integer(opcode))) {
            if (opcode == 8 && c.getNumberC3() >= 2 && c.getNumberC3() <= 5){
                    jLabelAnswer.setText(jLabelAnswer.getText() + " r"+c.getRc());
            } else if (opcode == 9 && c.getNumberC3() >= 2 && c.getNumberC3() <= 5){
                jLabelAnswer.setText(jLabelAnswer.getText() + " r"+c.getRc());
            } else if (opcode == 28 && c.getRc() != 0){
                jLabelAnswer.setText(jLabelAnswer.getText() + " r"+c.getRc());
            } else{
                jLabelAnswer.setText(jLabelAnswer.getText() + " r"+c.getRc());
            }
        }
        
        int[] c3Exists = {26, 27, 28, 29};
        Vector c3ExistsVector = arrayToVector(c3Exists);
        if (c3ExistsVector.contains(new Integer(opcode))) {
            if (c.getRc() == 0)
                jLabelAnswer.setText(jLabelAnswer.getText() + " "+c.getNumberC3());
        }

    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage(), "Error...", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_jButton1ActionPerformed

private static Vector arrayToVector(int[] array){
    Vector ans = new Vector();
    for (int i = 0; i < array.length; i++) {
        ans.addElement(new Integer(array[i]));
    }
    return ans;
}
    public static void main(String args[]) {
        try{
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
        } catch(Exception e) { e.printStackTrace(); } 
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabelAnswer;
    private javax.swing.JLabel jLabelAnswerCommandName;
    private javax.swing.JLabel jLabelC1;
    private javax.swing.JLabel jLabelC2;
    private javax.swing.JLabel jLabelC3;
    private javax.swing.JLabel jLabelNumber;
    private javax.swing.JLabel jLabelOpcode;
    private javax.swing.JLabel jLabelRa;
    private javax.swing.JLabel jLabelRb;
    private javax.swing.JLabel jLabelRc;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanelNumber;
    private javax.swing.JPanel jPanelOpcode;
    private javax.swing.JPanel jPanelRa;
    private javax.swing.JPanel jPanelRb;
    private javax.swing.JPanel jPanelRc;
    private javax.swing.JTextField jTextFieldInputCommand;
    // End of variables declaration//GEN-END:variables

}
